package com.sgcc.sx.pmos.common.dialog;

import android.content.Context;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.lxj.xpopup.core.DrawerPopupView;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.sx.pmos.common.adapter.GoodScreenAdapter;
import com.sgcc.sx.pmos.common.bean.StoreScreenBackBean;
import com.sgcc.sx.pmos.common.bean.StoreScreenBean;

import java.util.ArrayList;
import java.util.List;


/**
 * @author ChaoAJ
 * @describe 店铺筛选弹窗
 * @time 2022/8/29 17:55
 */
public class StoreScreenDialog extends DrawerPopupView {
    private OnSearchClickListener<StoreScreenBackBean> onSearchClickListener;

    public StoreScreenDialog(@NonNull Context context, OnSearchClickListener<StoreScreenBackBean> onSearchClickListener) {
        super(context);
        this.onSearchClickListener = onSearchClickListener;
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_store_screen_layout;
    }


    @Override
    protected void onCreate() {
        RecyclerView rvDataList = findViewById(R.id.rvDataList);
        rvDataList.setLayoutManager(new LinearLayoutManager(getContext()));
        GoodScreenAdapter goodScreenAdapter = new GoodScreenAdapter(getData());
        rvDataList.setAdapter(goodScreenAdapter);
        findViewById(R.id.tvReset).setOnClickListener(view -> goodScreenAdapter.setList(getData()));


        findViewById(R.id.tvSearch).setOnClickListener(view -> {
            List<StoreScreenBean> data = goodScreenAdapter.getData();

            StoreScreenBackBean storeScreenBackBean = new StoreScreenBackBean();

            for (StoreScreenBean datum : data) {
                switch (datum.getTitle()) {
                    case "企业类型":
                        for (StoreScreenBean.GoodScreenItemBean goodScreenItemBean : datum.getList()) {
                            if (goodScreenItemBean.isSelect()) {
                                storeScreenBackBean.setOwernType(goodScreenItemBean.getFlag());
                            }

                        }
                        break;

                    case "信用等级":
                        for (StoreScreenBean.GoodScreenItemBean goodScreenItemBean : datum.getList()) {
                            if (goodScreenItemBean.isSelect()) {
                                storeScreenBackBean.setCreditRating(goodScreenItemBean.getFlag());
                            }

                        }
                        break;

                    case "地理区域":
                        for (StoreScreenBean.GoodScreenItemBean goodScreenItemBean : datum.getList()) {
                            if (goodScreenItemBean.isSelect()) {
                                storeScreenBackBean.setGeogrregionId(goodScreenItemBean.getFlag());
                            }

                        }
                        break;

                    case "注册资本":
                        for (StoreScreenBean.GoodScreenItemBean goodScreenItemBean : datum.getList()) {
                            if (goodScreenItemBean.isSelect()) {
                                storeScreenBackBean.setRegcapital(goodScreenItemBean.getFlag());
                            }

                        }
                        break;

                    case "用户数量":

                        break;

                    case "年最大售电量":
                        for (StoreScreenBean.GoodScreenItemBean goodScreenItemBean : datum.getList()) {
                            if (goodScreenItemBean.isSelect()) {
                                storeScreenBackBean.setSaleEnergyYear(goodScreenItemBean.getFlag());
                            }
                        }

                        break;
                    case "在售商品数量":
                        for (StoreScreenBean.GoodScreenItemBean goodScreenItemBean : datum.getList()) {
                            if (goodScreenItemBean.isSelect()) {
                                storeScreenBackBean.setSaleMemberNum(goodScreenItemBean.getFlag());
                            }

                        }
                        break;


                }


            }

            onSearchClickListener.onClick(storeScreenBackBean);
            dismiss();


        });


    }


    private List<StoreScreenBean> getData() {
        List<StoreScreenBean> list = new ArrayList<>();

        List<StoreScreenBean.GoodScreenItemBean> list1 = new ArrayList<>();
        list1.add(new StoreScreenBean.GoodScreenItemBean(true, "不限", ""));
        list1.add(new StoreScreenBean.GoodScreenItemBean("国有企业", "1"));
        list1.add(new StoreScreenBean.GoodScreenItemBean("民营企业", "2"));
        list1.add(new StoreScreenBean.GoodScreenItemBean("集体企业", "5"));
        list1.add(new StoreScreenBean.GoodScreenItemBean("三资企业", "6"));
        list1.add(new StoreScreenBean.GoodScreenItemBean("其他", "3"));
//        list.add(new StoreScreenBean("企业类型", list1));


        List<StoreScreenBean.GoodScreenItemBean> list3 = new ArrayList<>();
        list3.add(new StoreScreenBean.GoodScreenItemBean(true, "不限", ""));
        list3.add(new StoreScreenBean.GoodScreenItemBean("AAA", "AAA"));
        list3.add(new StoreScreenBean.GoodScreenItemBean("AA", "AA"));
        list3.add(new StoreScreenBean.GoodScreenItemBean("A", "A"));
        list3.add(new StoreScreenBean.GoodScreenItemBean("B", "B"));
        list3.add(new StoreScreenBean.GoodScreenItemBean("C", "C"));
        list.add(new StoreScreenBean("信用等级", list3));


        List<StoreScreenBean.GoodScreenItemBean> list4 = new ArrayList<>();
        list4.add(new StoreScreenBean.GoodScreenItemBean(true, "不限", ""));
        list4.add(new StoreScreenBean.GoodScreenItemBean("太原市", "140100"));
        list4.add(new StoreScreenBean.GoodScreenItemBean("大同市", "140200"));
        list4.add(new StoreScreenBean.GoodScreenItemBean("阳泉市", "140300"));
        list4.add(new StoreScreenBean.GoodScreenItemBean("长治市", "140400"));
        list4.add(new StoreScreenBean.GoodScreenItemBean("晋城市", "140500"));
        list4.add(new StoreScreenBean.GoodScreenItemBean("朔州市", "140600"));
        list4.add(new StoreScreenBean.GoodScreenItemBean("晋中市", "140700"));
        list4.add(new StoreScreenBean.GoodScreenItemBean("运城市", "140800"));
        list4.add(new StoreScreenBean.GoodScreenItemBean("忻州市", "140900"));
        list4.add(new StoreScreenBean.GoodScreenItemBean("临汾市", "141000"));
        list4.add(new StoreScreenBean.GoodScreenItemBean("吕梁市", "141100"));
        list.add(new StoreScreenBean("地理区域", list4));

        List<StoreScreenBean.GoodScreenItemBean> list5 = new ArrayList<>();
        list5.add(new StoreScreenBean.GoodScreenItemBean(true, "不限", ""));
        list5.add(new StoreScreenBean.GoodScreenItemBean("1亿元以下", "1"));
        list5.add(new StoreScreenBean.GoodScreenItemBean("1-2亿元", "2"));
        list5.add(new StoreScreenBean.GoodScreenItemBean("2亿元以上", "3"));
//        list.add(new StoreScreenBean("注册资本", list5));


        List<StoreScreenBean.GoodScreenItemBean> list6 = new ArrayList<>();
        list6.add(new StoreScreenBean.GoodScreenItemBean(true, "不限", ""));
        list6.add(new StoreScreenBean.GoodScreenItemBean("0-50", ""));
        list6.add(new StoreScreenBean.GoodScreenItemBean("51-100", ""));
        list6.add(new StoreScreenBean.GoodScreenItemBean("101-500", ""));
        list6.add(new StoreScreenBean.GoodScreenItemBean("501-1000", ""));
        list6.add(new StoreScreenBean.GoodScreenItemBean("1001以上", ""));
        list.add(new StoreScreenBean("用户数量", list6));

        List<StoreScreenBean.GoodScreenItemBean> list7 = new ArrayList<>();
        list7.add(new StoreScreenBean.GoodScreenItemBean(true, "不限", ""));
        list7.add(new StoreScreenBean.GoodScreenItemBean("0-30亿千瓦时", "1"));
        list7.add(new StoreScreenBean.GoodScreenItemBean("30-60亿千瓦时", "2"));
        list.add(new StoreScreenBean("年最大售电量", list7));

        List<StoreScreenBean.GoodScreenItemBean> list8 = new ArrayList<>();
        list8.add(new StoreScreenBean.GoodScreenItemBean(true, "不限", ""));
        list8.add(new StoreScreenBean.GoodScreenItemBean("1-5", "1"));
        list8.add(new StoreScreenBean.GoodScreenItemBean("5-10", "2"));
        list8.add(new StoreScreenBean.GoodScreenItemBean("10-20", "3"));
        list8.add(new StoreScreenBean.GoodScreenItemBean("20-50", "4"));
        list8.add(new StoreScreenBean.GoodScreenItemBean("50以上", "5"));
        list.add(new StoreScreenBean("在售商品数量", list8));


        return list;
    }


}
